package suites.page {
	import suites.AbstractConfig;
	import suites.stub.InjectorStub;
	import suites.stub.RequestPageStub;

	import org.flexunit.asserts.assertEquals;
	import org.splink.deepsplink.boot.IDeepsplinkFacade;
	import org.splink.deepsplink.boot.TestBootstrapper;
	import org.splink.deepsplink.config.ConfigDataReader;
	import org.splink.deepsplink.page.IPage;
	import org.splink.deepsplink.page.params.PageParameter;

	/**
	 * Tests "hide-initshow-finalize" requestbuilder with completely syncronous pages
	 * 
	 * @author Max Kugland
	 */
	public class SyncronousGotoPageTest extends AbstractConfig {
		private static const PAGE_CLASS_CP : String = "suites.stub.RequestPageStub";		private static const PAGE_CLASS : Class = RequestPageStub;		private var _history : Array;

//TODO config with each requestbuilder type as root request 
//TODO mixed request order configurations 
//TODO and everything in asyncronous
//TODO async gotoPage with page changes during request processing


		public function createFacade() : IDeepsplinkFacade {
			_history = new Array();
			var facade : IDeepsplinkFacade;
			var fnc : Function = function(f : IDeepsplinkFacade) : void {
				facade = f;
				
				facade.addInjector(new InjectorStub(function(page : IPage) : void {
					if(page is RequestPageStub) {
						RequestPageStub(page).history = _history;
					}
				}));
			};
			
			new TestBootstrapper(new ConfigDataReader(<config eagerPages="true">
							<page id={ROOT} clazz={PAGE_CLASS_CP} title={PAGE_TITLE + ROOT} >
								<page id={P_404} clazz={PAGE_CLASS_CP} title={PAGE_TITLE + P_404} />
								<page id="1" clazz={PAGE_CLASS_CP} title={PAGE_TITLE + "1"} />
								<page id="2" clazz={PAGE_CLASS_CP} title={PAGE_TITLE + "2"}  >
									<page id="3" clazz={PAGE_CLASS_CP} title={PAGE_TITLE + "3"} />
									<page id="4" clazz={PAGE_CLASS_CP} title={PAGE_TITLE + "4"} />
								</page>
								<page id="5" clazz={PAGE_CLASS_CP} title={PAGE_TITLE + "5"}  >
									<page id="6" clazz={PAGE_CLASS_CP} title={PAGE_TITLE + "6"} >
										<page id="7" clazz={PAGE_CLASS_CP} title={PAGE_TITLE + "7"} />
										<page id="8" clazz={PAGE_CLASS_CP} title={PAGE_TITLE + "8"} >
											<page id="9" clazz={PAGE_CLASS_CP} title={PAGE_TITLE + "9"} />
											<page id="10" clazz={PAGE_CLASS_CP} title={PAGE_TITLE + "10"} />
										</page>
									</page>
								</page>
							</page>
							<home id={HOME} />
							<notfound redirect={P_404} />
						</config>).read(), createBootStrategy(fnc, pageCount));
			return facade;
		}

		private function clearHistory() : void {
			_history.splice(0, _history.length);			
		}

		[Test]
		public function autoHome() : void {
			createFacade();
			
			assertEquals("initialize-root", _history[0]);			assertEquals("show-root", _history[1]);			assertEquals("initialize-1", _history[2]);			assertEquals("show-1", _history[3]);
			assertEquals(4, _history.length);
		}

		[Test]
		public function showLevel1() : void {
			var facade : IDeepsplinkFacade = createFacade();
			clearHistory();
			facade.navigationCommand.gotoPage("2");
			
			assertEquals("hide-1", _history[0]);
			assertEquals("initialize-2", _history[1]);
			assertEquals("show-2", _history[2]);
			assertEquals("finalize-1", _history[3]);
			assertEquals(4, _history.length);
		}

		[Test]
		public function showLevel2() : void {
			var facade : IDeepsplinkFacade = createFacade();
			clearHistory();
			facade.navigationCommand.gotoPage("3");
			
			assertEquals("hide-1", _history[0]);
			assertEquals("initialize-2", _history[1]);
			assertEquals("show-2", _history[2]);
			assertEquals("initialize-3", _history[3]);			assertEquals("show-3", _history[4]);			assertEquals("finalize-1", _history[5]);
			assertEquals(6, _history.length);		}

		[Test]
		public function showLevel3() : void {
			var facade : IDeepsplinkFacade = createFacade();
			clearHistory();
			facade.navigationCommand.gotoPage("8");
			
			assertEquals("hide-1", _history[0]);
			assertEquals("initialize-5", _history[1]);
			assertEquals("show-5", _history[2]);
			assertEquals("initialize-6", _history[3]);
			assertEquals("show-6", _history[4]);			assertEquals("initialize-8", _history[5]);			assertEquals("show-8", _history[6]);			assertEquals("finalize-1", _history[7]);
			assertEquals(8, _history.length);
		}

		[Test]
		public function showLevel4() : void {
			var facade : IDeepsplinkFacade = createFacade();
			clearHistory();
			facade.navigationCommand.gotoPage("10");
			
			assertEquals("hide-1", _history[0]);
			assertEquals("initialize-5", _history[1]);
			assertEquals("show-5", _history[2]);
			assertEquals("initialize-6", _history[3]);
			assertEquals("show-6", _history[4]);
			assertEquals("initialize-8", _history[5]);
			assertEquals("show-8", _history[6]);
			assertEquals("initialize-10", _history[7]);
			assertEquals("show-10", _history[8]);
			assertEquals("finalize-1", _history[9]);
			assertEquals(10, _history.length);
		}

		[Test]
		public function navigateLevel1() : void {
			var facade : IDeepsplinkFacade = createFacade();
			clearHistory();
			
			facade.navigationCommand.gotoPage("2");
			assertEquals("hide-1", _history[0]);
			assertEquals("initialize-2", _history[1]);
			assertEquals("show-2", _history[2]);
			assertEquals("finalize-1", _history[3]);
			assertEquals(4, _history.length);
			clearHistory();
						facade.navigationCommand.gotoPage("5");
			assertEquals("hide-2", _history[0]);
			assertEquals("initialize-5", _history[1]);
			assertEquals("show-5", _history[2]);
			assertEquals("finalize-2", _history[3]);
			assertEquals(4, _history.length);
			clearHistory();
						facade.navigationCommand.gotoPage("1");
			assertEquals("hide-5", _history[0]);
			assertEquals("initialize-1", _history[1]);
			assertEquals("show-1", _history[2]);
			assertEquals("finalize-5", _history[3]);
			assertEquals(4, _history.length);
		}

		[Test]
		public function navigateLevel2() : void {
			var facade : IDeepsplinkFacade = createFacade();
			clearHistory();
			
			facade.navigationCommand.gotoPage("3");
			assertEquals("hide-1", _history[0]);
			assertEquals("initialize-2", _history[1]);
			assertEquals("show-2", _history[2]);
			assertEquals("initialize-3", _history[3]);
			assertEquals("show-3", _history[4]);
			assertEquals("finalize-1", _history[5]);
			assertEquals(6, _history.length);
			clearHistory();
			
			facade.navigationCommand.gotoPage("4");
			assertEquals("hide-3", _history[0]);
			assertEquals("initialize-4", _history[1]);
			assertEquals("show-4", _history[2]);
			assertEquals("finalize-3", _history[3]);
			assertEquals(4, _history.length);
			clearHistory();
			
			facade.navigationCommand.gotoPage("3");
			assertEquals("hide-4", _history[0]);
			assertEquals("initialize-3", _history[1]);
			assertEquals("show-3", _history[2]);
			assertEquals("finalize-4", _history[3]);
			assertEquals(4, _history.length);
		}

		[Test]
		public function navigateLevel3() : void {
			var facade : IDeepsplinkFacade = createFacade();
			clearHistory();
			
			facade.navigationCommand.gotoPage("7");
			assertEquals("hide-1", _history[0]);
			assertEquals("initialize-5", _history[1]);
			assertEquals("show-5", _history[2]);
			assertEquals("initialize-6", _history[3]);
			assertEquals("show-6", _history[4]);
			assertEquals("initialize-7", _history[5]);
			assertEquals("show-7", _history[6]);
			assertEquals("finalize-1", _history[7]);
			assertEquals(8, _history.length);
			clearHistory();
			
			facade.navigationCommand.gotoPage("8");
			assertEquals("hide-7", _history[0]);
			assertEquals("initialize-8", _history[1]);
			assertEquals("show-8", _history[2]);
			assertEquals("finalize-7", _history[3]);
			assertEquals(4, _history.length);
			clearHistory();
			
			facade.navigationCommand.gotoPage("7");
			assertEquals("hide-8", _history[0]);
			assertEquals("initialize-7", _history[1]);
			assertEquals("show-7", _history[2]);
			assertEquals("finalize-8", _history[3]);
			assertEquals(4, _history.length);
		}

		[Test]
		public function navigateLevel1And2() : void {
			var facade : IDeepsplinkFacade = createFacade();
			clearHistory();
			
			facade.navigationCommand.gotoPage("3");
			assertEquals("hide-1", _history[0]);
			assertEquals("initialize-2", _history[1]);
			assertEquals("show-2", _history[2]);
			assertEquals("initialize-3", _history[3]);
			assertEquals("show-3", _history[4]);
			assertEquals("finalize-1", _history[5]);
			assertEquals(6, _history.length);
			clearHistory();
			
			facade.navigationCommand.gotoPage("5");
			assertEquals("hide-3", _history[0]);
			assertEquals("hide-2", _history[1]);
			assertEquals("initialize-5", _history[2]);
			assertEquals("show-5", _history[3]);			assertEquals("finalize-3", _history[4]);			assertEquals("finalize-2", _history[5]);
			assertEquals(6, _history.length);
			clearHistory();
			
			facade.navigationCommand.gotoPage("4");
			assertEquals("hide-5", _history[0]);
			assertEquals("initialize-2", _history[1]);
			assertEquals("show-2", _history[2]);
			assertEquals("initialize-4", _history[3]);
			assertEquals("show-4", _history[4]);
			assertEquals("finalize-5", _history[5]);
			assertEquals(6, _history.length);		}

		[Test]
		public function navigateLevel1And3() : void {
			var facade : IDeepsplinkFacade = createFacade();
			clearHistory();
			
			facade.navigationCommand.gotoPage("7");
			assertEquals("hide-1", _history[0]);
			assertEquals("initialize-5", _history[1]);
			assertEquals("show-5", _history[2]);
			assertEquals("initialize-6", _history[3]);
			assertEquals("show-6", _history[4]);
			assertEquals("initialize-7", _history[5]);
			assertEquals("show-7", _history[6]);
			assertEquals("finalize-1", _history[7]);
			assertEquals(8, _history.length);
			clearHistory();
			
			facade.navigationCommand.gotoPage("5");
			assertEquals("hide-7", _history[0]);
			assertEquals("hide-6", _history[1]);
			assertEquals("finalize-7", _history[2]);
			assertEquals("finalize-6", _history[3]);
			assertEquals(4, _history.length);
			clearHistory();
			
			facade.navigationCommand.gotoPage("8");
			assertEquals("initialize-6", _history[0]);
			assertEquals("show-6", _history[1]);
			assertEquals("initialize-8", _history[2]);
			assertEquals("show-8", _history[3]);
			assertEquals(4, _history.length);
			clearHistory();
			
			facade.navigationCommand.gotoPage("1");
			assertEquals("hide-8", _history[0]);
			assertEquals("hide-6", _history[1]);
			assertEquals("hide-5", _history[2]);
			assertEquals("initialize-1", _history[3]);			assertEquals("show-1", _history[4]);			assertEquals("finalize-8", _history[5]);			assertEquals("finalize-6", _history[6]);			assertEquals("finalize-5", _history[7]);
			assertEquals(8, _history.length);
		}
		
		[Test]
		public function navigateLevel1And2And3() : void {
			var facade : IDeepsplinkFacade = createFacade();
			clearHistory();
			
			facade.navigationCommand.gotoPage("8");
			assertEquals("hide-1", _history[0]);
			assertEquals("initialize-5", _history[1]);
			assertEquals("show-5", _history[2]);
			assertEquals("initialize-6", _history[3]);
			assertEquals("show-6", _history[4]);
			assertEquals("initialize-8", _history[5]);
			assertEquals("show-8", _history[6]);
			assertEquals("finalize-1", _history[7]);
			assertEquals(8, _history.length);
			clearHistory();
			
			facade.navigationCommand.gotoPage("6");
			assertEquals("hide-8", _history[0]);
			assertEquals("finalize-8", _history[1]);
			assertEquals(2, _history.length);
			clearHistory();
			
			facade.navigationCommand.gotoPage("7");
			assertEquals("initialize-7", _history[0]);
			assertEquals("show-7", _history[1]);
			assertEquals(2, _history.length);
			clearHistory();
			
			facade.navigationCommand.gotoPage("3");
			assertEquals("hide-7", _history[0]);
			assertEquals("hide-6", _history[1]);			assertEquals("hide-5", _history[2]);			assertEquals("initialize-2", _history[3]);			assertEquals("show-2", _history[4]);			assertEquals("initialize-3", _history[5]);			assertEquals("show-3", _history[6]);			assertEquals("finalize-7", _history[7]);			assertEquals("finalize-6", _history[8]);			assertEquals("finalize-5", _history[9]);
			assertEquals(10, _history.length);
			clearHistory();
			
			facade.navigationCommand.gotoPage("4");
			assertEquals("hide-3", _history[0]);
			assertEquals("initialize-4", _history[1]);
			assertEquals("show-4", _history[2]);
			assertEquals("finalize-3", _history[3]);
			assertEquals(4, _history.length);
			clearHistory();
			
			facade.navigationCommand.gotoPage("1");
			assertEquals("hide-4", _history[0]);
			assertEquals("hide-2", _history[1]);
			assertEquals("initialize-1", _history[2]);
			assertEquals("show-1", _history[3]);			assertEquals("finalize-4", _history[4]);			assertEquals("finalize-2", _history[5]);
			assertEquals(6, _history.length);
		}
		
		[Test]
		public function showLevel1Params() : void {
			var facade : IDeepsplinkFacade = createFacade();
			clearHistory();
			facade.navigationCommand.gotoPage("2", [new PageParameter("param1", "hello"), new PageParameter("param2", "world")]);
			
			assertEquals("hide-1", _history[0]);			assertEquals("params-root-2", _history[1]);			assertEquals("params-2-2", _history[2]);
			assertEquals("initialize-2", _history[3]);
			assertEquals("show-2", _history[4]);
			assertEquals("finalize-1", _history[5]);
			assertEquals(6, _history.length);
		}
		
		[Test]
		public function showLevel2Params() : void {
			var facade : IDeepsplinkFacade = createFacade();
			clearHistory();
			facade.navigationCommand.gotoPage("3", [new PageParameter("param1", "hello"), new PageParameter("param2", "world")]);
			
			assertEquals("hide-1", _history[0]);
			assertEquals("params-root-2", _history[1]);
			assertEquals("params-2-2", _history[2]);
			assertEquals("initialize-2", _history[3]);
			assertEquals("show-2", _history[4]);
			assertEquals("params-3-2", _history[5]);
			assertEquals("initialize-3", _history[6]);
			assertEquals("show-3", _history[7]);
			assertEquals("finalize-1", _history[8]);
			assertEquals(9, _history.length);
		}
		
		[Test]
		public function showLevel4Params() : void {
			var facade : IDeepsplinkFacade = createFacade();
			clearHistory();
			facade.navigationCommand.gotoPage("10", [new PageParameter("param1", "hello"), new PageParameter("param2", "world")]);
			
			assertEquals("hide-1", _history[0]);
			assertEquals("params-root-2", _history[1]);
			assertEquals("params-5-2", _history[2]);
			assertEquals("initialize-5", _history[3]);
			assertEquals("show-5", _history[4]);
			assertEquals("params-6-2", _history[5]);
			assertEquals("initialize-6", _history[6]);
			assertEquals("show-6", _history[7]);
			assertEquals("params-8-2", _history[8]);
			assertEquals("initialize-8", _history[9]);
			assertEquals("show-8", _history[10]);
			assertEquals("params-10-2", _history[11]);
			assertEquals("initialize-10", _history[12]);
			assertEquals("show-10", _history[13]);
			assertEquals("finalize-1", _history[14]);
			assertEquals(15, _history.length);
		}
	
		[Test]
		public function navigateLevel1Params() : void {
			var facade : IDeepsplinkFacade = createFacade();
			clearHistory();
			
			facade.navigationCommand.gotoPage("2", [new PageParameter("param1", "hello"), new PageParameter("param2", "world")]);
			assertEquals("hide-1", _history[0]);
			assertEquals("params-root-2", _history[1]);			assertEquals("params-2-2", _history[2]);
			assertEquals("initialize-2", _history[3]);
			assertEquals("show-2", _history[4]);
			assertEquals("finalize-1", _history[5]);
			assertEquals(6, _history.length);
			clearHistory();
			
			facade.navigationCommand.gotoPage("5", [new PageParameter("param1", "hello")]);
			assertEquals("hide-2", _history[0]);
			assertEquals("params-root-1", _history[1]);
			assertEquals("params-5-1", _history[2]);
			assertEquals("initialize-5", _history[3]);
			assertEquals("show-5", _history[4]);
			assertEquals("finalize-2", _history[5]);
			assertEquals(6, _history.length);
			clearHistory();
			
			facade.navigationCommand.gotoPage("1", [new PageParameter("param1", "hello"), new PageParameter("param2", "world")]);
			assertEquals("hide-5", _history[0]);
			assertEquals("params-root-2", _history[1]);
			assertEquals("params-1-2", _history[2]);
			assertEquals("initialize-1", _history[3]);
			assertEquals("show-1", _history[4]);
			assertEquals("finalize-5", _history[5]);
			assertEquals(6, _history.length);
		}
		
		[Test]
		public function navigateLevel3Params() : void {
			var facade : IDeepsplinkFacade = createFacade();
			clearHistory();
			
			facade.navigationCommand.gotoPage("7", [new PageParameter("param1", "hello")]);
			assertEquals("hide-1", _history[0]);			assertEquals("params-root-1", _history[1]);
			assertEquals("params-5-1", _history[2]);
			assertEquals("initialize-5", _history[3]);
			assertEquals("show-5", _history[4]);
			assertEquals("params-6-1", _history[5]);
			assertEquals("initialize-6", _history[6]);
			assertEquals("show-6", _history[7]);
			assertEquals("params-7-1", _history[8]);
			assertEquals("initialize-7", _history[9]);
			assertEquals("show-7", _history[10]);
			assertEquals("finalize-1", _history[11]);
			assertEquals(12, _history.length);
			clearHistory();
			
			// params change
			facade.navigationCommand.gotoPage("8", [new PageParameter("param1", "hello"), new PageParameter("param2", "world")]);
			assertEquals("hide-7", _history[0]);
			assertEquals("params-root-2", _history[1]);			assertEquals("params-5-2", _history[2]);			assertEquals("params-6-2", _history[3]);
			assertEquals("params-8-2", _history[4]);
			assertEquals("initialize-8", _history[5]);
			assertEquals("show-8", _history[6]);
			assertEquals("finalize-7", _history[7]);
			assertEquals(8, _history.length);
			clearHistory();
			
			//params don't change
			facade.navigationCommand.gotoPage("7", [new PageParameter("param1", "hello"), new PageParameter("param2", "world")]);
			assertEquals("hide-8", _history[0]);
			assertEquals("params-7-2", _history[1]);
			assertEquals("initialize-7", _history[2]);
			assertEquals("show-7", _history[3]);
			assertEquals("finalize-8", _history[4]);
			assertEquals(5, _history.length);
		}
		
		[Test]
		public function navigateLevel1And2Params() : void {
			var facade : IDeepsplinkFacade = createFacade();
			clearHistory();
			
			facade.navigationCommand.gotoPage("3", [new PageParameter("param1", "hello")]);
			assertEquals("hide-1", _history[0]);
			assertEquals("params-root-1", _history[1]);
			assertEquals("params-2-1", _history[2]);
			assertEquals("initialize-2", _history[3]);
			assertEquals("show-2", _history[4]);
			assertEquals("params-3-1", _history[5]);
			assertEquals("initialize-3", _history[6]);
			assertEquals("show-3", _history[7]);
			assertEquals("finalize-1", _history[8]);
			assertEquals(9, _history.length);
			clearHistory();
			
			// params change
			facade.navigationCommand.gotoPage("5", [new PageParameter("param1", "hello"), new PageParameter("param2", "world")]);
			assertEquals("hide-3", _history[0]);
			assertEquals("hide-2", _history[1]);
			assertEquals("params-root-2", _history[2]);
			assertEquals("params-5-2", _history[3]);
			assertEquals("initialize-5", _history[4]);
			assertEquals("show-5", _history[5]);
			assertEquals("finalize-3", _history[6]);
			assertEquals("finalize-2", _history[7]);
			assertEquals(8, _history.length);
			clearHistory();
			
			// params change
			facade.navigationCommand.gotoPage("4", [new PageParameter("param1", "hello")]);
			assertEquals("hide-5", _history[0]);
			assertEquals("params-root-1", _history[1]);			assertEquals("params-2-1", _history[2]);
			assertEquals("initialize-2", _history[3]);
			assertEquals("show-2", _history[4]);
			assertEquals("params-4-1", _history[5]);
			assertEquals("initialize-4", _history[6]);
			assertEquals("show-4", _history[7]);
			assertEquals("finalize-5", _history[8]);
			assertEquals(9, _history.length);
		}
		
		[Test]
		public function navigateLevel1And3Params() : void {
			var facade : IDeepsplinkFacade = createFacade();
			clearHistory();
			
			facade.navigationCommand.gotoPage("7", [new PageParameter("param1", "hello")]);
			assertEquals("hide-1", _history[0]);
			assertEquals("params-root-1", _history[1]);
			assertEquals("params-5-1", _history[2]);
			assertEquals("initialize-5", _history[3]);
			assertEquals("show-5", _history[4]);
			assertEquals("params-6-1", _history[5]);
			assertEquals("initialize-6", _history[6]);
			assertEquals("show-6", _history[7]);
			assertEquals("params-7-1", _history[8]);
			assertEquals("initialize-7", _history[9]);
			assertEquals("show-7", _history[10]);
			assertEquals("finalize-1", _history[11]);
			assertEquals(12, _history.length);
			clearHistory();
			
			// params don't change
			facade.navigationCommand.gotoPage("5", [new PageParameter("param1", "hello")]);
			assertEquals("hide-7", _history[0]);
			assertEquals("hide-6", _history[1]);
			assertEquals("finalize-7", _history[2]);
			assertEquals("finalize-6", _history[3]);
			assertEquals(4, _history.length);
			clearHistory();
			
			facade.navigationCommand.gotoPage("8", [new PageParameter("param1", "hello"), new PageParameter("param2", "world")]);
			assertEquals("params-root-2", _history[0]);
			assertEquals("params-5-2", _history[1]);			assertEquals("params-6-2", _history[2]);
			assertEquals("initialize-6", _history[3]);
			assertEquals("show-6", _history[4]);
			assertEquals("params-8-2", _history[5]);
			assertEquals("initialize-8", _history[6]);
			assertEquals("show-8", _history[7]);
			assertEquals(8, _history.length);
			clearHistory();
			
			// params don't change
			facade.navigationCommand.gotoPage("1", [new PageParameter("param1", "hello"), new PageParameter("param2", "world")]);
			assertEquals("hide-8", _history[0]);
			assertEquals("hide-6", _history[1]);
			assertEquals("hide-5", _history[2]);
			assertEquals("params-1-2", _history[3]);
			assertEquals("initialize-1", _history[4]);
			assertEquals("show-1", _history[5]);
			assertEquals("finalize-8", _history[6]);
			assertEquals("finalize-6", _history[7]);
			assertEquals("finalize-5", _history[8]);
			assertEquals(9, _history.length);
		}
		
		[Test]
		public function navigateLevel1And2And3Params() : void {
			var facade : IDeepsplinkFacade = createFacade();
			clearHistory();
			
			facade.navigationCommand.gotoPage("8", [new PageParameter("param1", "hello")]);
			assertEquals("hide-1", _history[0]);
			assertEquals("params-root-1", _history[1]);
			assertEquals("params-5-1", _history[2]);
			assertEquals("initialize-5", _history[3]);
			assertEquals("show-5", _history[4]);
			assertEquals("params-6-1", _history[5]);
			assertEquals("initialize-6", _history[6]);
			assertEquals("show-6", _history[7]);
			assertEquals("params-8-1", _history[8]);
			assertEquals("initialize-8", _history[9]);
			assertEquals("show-8", _history[10]);
			assertEquals("finalize-1", _history[11]);
			assertEquals(12, _history.length);
			clearHistory();
			
			facade.navigationCommand.gotoPage("6", [new PageParameter("param1", "hello"), new PageParameter("param2", "world")]);
			assertEquals("hide-8", _history[0]);
			assertEquals("params-root-2", _history[1]);
			assertEquals("params-5-2", _history[2]);
			assertEquals("params-6-2", _history[3]);
			assertEquals("finalize-8", _history[4]);
			assertEquals(5, _history.length);
			clearHistory();
			
			facade.navigationCommand.gotoPage("7", [new PageParameter("param1", "hello")]);
			assertEquals("params-root-1", _history[0]);			assertEquals("params-5-1", _history[1]);			assertEquals("params-6-1", _history[2]);
			assertEquals("params-7-1", _history[3]);
			assertEquals("initialize-7", _history[4]);
			assertEquals("show-7", _history[5]);
			assertEquals(6, _history.length);
			clearHistory();
			
			facade.navigationCommand.gotoPage("3", [new PageParameter("param1", "hello"), new PageParameter("param2", "world")]);
			assertEquals("hide-7", _history[0]);
			assertEquals("hide-6", _history[1]);
			assertEquals("hide-5", _history[2]);
			assertEquals("params-root-2", _history[3]);
			assertEquals("params-2-2", _history[4]);
			assertEquals("initialize-2", _history[5]);
			assertEquals("show-2", _history[6]);
			assertEquals("params-3-2", _history[7]);
			assertEquals("initialize-3", _history[8]);
			assertEquals("show-3", _history[9]);
			assertEquals("finalize-7", _history[10]);
			assertEquals("finalize-6", _history[11]);
			assertEquals("finalize-5", _history[12]);
			assertEquals(13, _history.length);
			clearHistory();
			
			facade.navigationCommand.gotoPage("4", [new PageParameter("param1", "hello")]);
			assertEquals("hide-3", _history[0]);
			assertEquals("params-root-1", _history[1]);
			assertEquals("params-2-1", _history[2]);			assertEquals("params-4-1", _history[3]);
			assertEquals("initialize-4", _history[4]);
			assertEquals("show-4", _history[5]);
			assertEquals("finalize-3", _history[6]);
			assertEquals(7, _history.length);
			clearHistory();
			
			// params don't change
			facade.navigationCommand.gotoPage("1", [new PageParameter("param1", "hello")]);
			assertEquals("hide-4", _history[0]);
			assertEquals("hide-2", _history[1]);
			assertEquals("params-1-1", _history[2]);
			assertEquals("initialize-1", _history[3]);
			assertEquals("show-1", _history[4]);
			assertEquals("finalize-4", _history[5]);
			assertEquals("finalize-2", _history[6]);
			assertEquals(7, _history.length);
		}		
	}
}